<?php

namespace app\admin\model;

use think\Model;

class SpeechGrade extends Model
{
    // 表名
    protected $name = 'speech_grade';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'calltime_text',
        'routernum_text',
        'faqnum_text'
    ];
    

    
    public function getRouternumList()
    {
        return ['2) unsigne' => __('2) unsigne')];
    }     

    public function getFaqnumList()
    {
        return ['1) unsigne' => __('1) unsigne')];
    }     


    public function getCalltimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['calltime'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getRouternumTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['routernum'];
        $list = $this->getRouternumList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getFaqnumTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['faqnum'];
        $list = $this->getFaqnumList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setCalltimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


    public function admin()
    {
        return $this->belongsTo('Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function speech()
    {
        return $this->belongsTo('Speech', 'speech_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
